home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10855 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  71 lines

  1. Path: uuneo.neosoft.com!usenet
  2. From: Wmatthew@lan-aces.com (W. Matthews)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Virtual Base Class
  5. Date: 11 Mar 1996 15:26:55 GMT
  6. Organization: LAN-ACES, Inc.
  7. Message-ID: <4i1gnv$b7i@uuneo.neosoft.com>
  8. References: <313F98D0.102E@ucla.edu>
  9. NNTP-Posting-Host: 198.65.178.8
  10. X-Newsreader: WinVN 0.92.5
  11.  
  12. In article <313F98D0.102E@ucla.edu>, Dennis Rahaman <dennisr@ucla.edu> says:
  13. >
  14. >This is what I want to do:
  15. >
  16. >              a
  17. >            /   \
  18. >           b     c
  19. >            \   /
  20. >              d
  21. >
  22. >
  23. >class a
  24. >  {
  25. >  //...
  26. >  };
  27. >
  28. >class b : public virtual a
  29. >  {
  30. >  //...
  31. >  };
  32. >
  33. >class c : public virtual b
  34. >  {
  35. >  //...
  36. >  };
  37. >
  38. >class d : public b, public c
  39. >  {
  40. >  //...
  41. >  };
  42. >
  43. >
  44. >void f ()
  45. >  {
  46. >  a a1;
  47. >  d* pd = (d*) &a1;  // error: can't cast virtual base to derived
  48. >  }
  49. >
  50. >///////////////////////////////////////////////////////////
  51. >Can someone explain why I can't cast a virtual base class to a derived 
  52. >class?
  53. >
  54. >What should I do instead?
  55. >
  56. >Any help would be appreciated.
  57. >
  58. >- Dennis
  59. I would surmise that this is due to the fact that the virtual base does not
  60. have the entire memory picture of the derived class.  Anything declared in
  61. the derived class would not always have a counter part in that virtaul base.
  62. ______________________________________________
  63. |Wyatt Matthews:       Tech Support Department |
  64. |WMATTHEW@LAN-ACES.COM        -Internet-       |
  65. |WMATTHEW.MHS@LAN-ACES          -MHS-          |
  66. |LAN-ACES Tech Support      (713)890-9786      |
  67. |LAN-ACES BBS               (713)890-9790      |
  68. |LAN-ACES Fax               (713)890-9731      |
  69. |LAN-ACES Sales             (713)890-9787      |
  70. ______________________________________________
  71.